#pragma once
#include <sys/types.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <string>

class InetAddr
{
public:
    InetAddr(sockaddr_in &addr)
        :_addr(addr)
    {
        _port = ntohs(addr.sin_port);
        _ip = inet_ntoa(addr.sin_addr);
    }

    uint16_t Port()
    {
        return _port;
    }

    std::string Ip()
    {
        return _ip;
    }
    
    std::string AddrMessage()
    {
        return "[" + _ip + " | " + std::to_string(_port) + "]";
    }

    bool operator==(InetAddr &tmp)
    {
        return tmp._ip == _ip && tmp._port == _port;
    }

    sockaddr_in& Sockaddr()
    {
        return _addr;
    }
private:
    sockaddr_in _addr;
    uint16_t _port;
    std::string _ip;
};